package cn.xaut.XAUT迎春杯预热;

import static java.lang.Math.*;
import java.util.Scanner;

/**
 * F - 最短区间
 */
public class demoF_2 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int s = input.nextInt();
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = input.nextInt();

        int res = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = i; j < n; j++) {
                sum += a[j];
                if (sum >= s) {
                    res = min(res, j - i + 1);
                }
            }
        }
        System.out.println(res == Integer.MAX_VALUE ? 0 : res);
    }
}
